package com.oschat.controller;

import com.oschat.annotation.GlobalInterceptor;
import com.oschat.entity.enums.ResponseCodeEnum;
import com.oschat.entity.po.GroupInfo;
import com.oschat.entity.po.UserInfoPretty;
import com.oschat.entity.query.GroupInfoQuery;
import com.oschat.entity.query.UserInfoPrettyQuery;
import com.oschat.entity.vo.PaginationResultVO;
import com.oschat.entity.vo.ResponseVO;
import com.oschat.exception.BusinessException;
import com.oschat.service.GroupInfoService;
import com.oschat.service.UserInfoPrettyService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/8/19 23:10
 */
@RestController("adminGroupController")
@RequestMapping("/admin")
public class AdminGroupController extends ABaseController{
    @Resource
    private GroupInfoService groupInfoService;

    /**
     * @description: 管理员展示界面接口
     * @author Administrator
     * @date 2025/8/14 19:29
     * @version 1.0
     */
    @RequestMapping("/loadGroup")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO loadGroup(GroupInfoQuery query) {
        query.setOrderBy("create_time desc");
        query.setQueryMemberCount(true);
        query.setQueryGroupOwnerName(true);
        PaginationResultVO result = groupInfoService.findListByPage(query);
        return getSuccessResponseVO(result);
    }

    /**
     * @description: 解散群组
     * @author Administrator
     * @date 2025/8/14 19:29
     * @version 1.0
     */
    @RequestMapping("/dissolutionGroup")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO dissolutionGroup(@NotEmpty String groupId) {
        GroupInfo groupInfo = groupInfoService.getGroupInfoByGroupId(groupId);
        if (null == groupInfo){
            throw new BusinessException(ResponseCodeEnum.CODE_600);
        }
        groupInfoService.dissolutionGroup(groupInfo.getGroupOwnerId(),groupId);
        return getSuccessResponseVO(null);
    }
}
